package main;



import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author user
 */
public class LuckyCoinDesign {

    public int width;
    public int height;
    public int sceneMode;
    public Image imgItem;
    public Image imgBackItem;
    public Image imgSmallLed;

    public LuckyCoinDesign(int width, int height, int sceneMode) {
        this.width = width;
        this.height = height;
        this.sceneMode = sceneMode;
    }

   

    public TiledLayer creatBottomBar() {
        try {
            Image img =Utils.loadImage("bottom_bar_piece.png");
            TiledLayer bg = new TiledLayer(width / img.getWidth(), 1, img, img.getWidth(), img.getHeight());
            for (int row = 0; row < bg.getRows(); row++) {
                for (int col = 0; col < bg.getColumns(); col++) {
                    bg.setCell(col, row, 1);
                }
            }
            return bg;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public TiledLayer getSelectedMenu(int boxWidth) {
        try {
            Image img = Utils.loadImage("sub_menu_color.png");
            TiledLayer selectMenu = new TiledLayer(boxWidth / img.getWidth(), 1, img, img.getWidth(), img.getHeight());
            for (int row = 0; row < selectMenu.getRows(); row++) {
                for (int col = 0; col < selectMenu.getColumns(); col++) {
                    selectMenu.setCell(col, row, 1);
                }
            }
            return selectMenu;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Image getImgSmallLed() {
        try {
            if (imgSmallLed == null) {
                imgSmallLed = Utils.loadImage("smallLed.png");
            }
            return imgSmallLed;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getSmallLed() {
        try {
            Sprite smallLed = new Sprite(getImgSmallLed(), getImgSmallLed().getWidth() / 4, getImgSmallLed().getHeight());
            int[] seq = {0, 1, 2, 3};
            smallLed.setFrameSequence(seq);
            return smallLed;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getBigLed() {
        try {
            Image img = Utils.loadImage("bigLed.png");
            Sprite bigLed = new Sprite(img, img.getWidth() / 4, img.getHeight());
            int[] seq = {0, 1, 2, 3};
            bigLed.setFrameSequence(seq);
            return bigLed;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public TiledLayer getTextBox(int boxWidth) {
        try {
            Image img =Utils.loadImage("textBox.png");
            int cellWidth = img.getWidth() / 3;
            TiledLayer textBox = new TiledLayer(boxWidth / cellWidth, 1, img, cellWidth, img.getHeight());
            for (int row = 0; row < textBox.getRows(); row++) {
                for (int col = 0; col < textBox.getColumns(); col++) {
                    if (col == 0) {
                        textBox.setCell(col, row, 1);
                    } else if (col == textBox.getColumns() - 1) {
                        textBox.setCell(col, row, 3);
                    } else {
                        textBox.setCell(col, row, 2);
                    }
                }
            }
            return textBox;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Image getImageItem() {
        try {
            if (imgItem == null) {
                imgItem = Utils.loadImage("item.png");
            }
            return imgItem;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getItem(int type, boolean isSmall) {
        try {
            Sprite item = new Sprite(getImageItem(), getImageItem().getWidth() / 17, getImageItem().getHeight());
            int[] seq = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
            item.setFrameSequence(seq);
            if (type == LuckyCoinCanvas.ITEM_MORE_TIME) {
                item.setFrame(0);
            } else if (type == LuckyCoinCanvas.ITEM_APPLE) {
                if (!isSmall) {
                    item.setFrame(1);
                } else {
                    item.setFrame(2);
                }
            } else if (type == LuckyCoinCanvas.ITEM_ORANGE) {
                if (!isSmall) {
                    item.setFrame(3);
                } else {
                    item.setFrame(4);
                }
            } else if (type == LuckyCoinCanvas.ITEM_MELLON) {
                if (!isSmall) {
                    item.setFrame(5);
                } else {
                    item.setFrame(6);
                }
            } else if (type == LuckyCoinCanvas.ITEM_BELL) {
                if (!isSmall) {
                    item.setFrame(7);
                } else {
                    item.setFrame(8);
                }
            } else if (type == LuckyCoinCanvas.ITEM_STAR) {
                if (!isSmall) {
                    item.setFrame(9);
                } else {
                    item.setFrame(10);
                }
            } else if (type == LuckyCoinCanvas.ITEM_WATER_MELLON) {
                if (!isSmall) {
                    item.setFrame(11);
                } else {
                    item.setFrame(12);
                }
            } else if (type == LuckyCoinCanvas.ITEM_SEVEN) {
                if (!isSmall) {
                    item.setFrame(13);
                } else {
                    item.setFrame(14);
                }
            } else if (type == LuckyCoinCanvas.ITEM_BAR) {
                if (!isSmall) {
                    item.setFrame(15);
                } else {
                    item.setFrame(16);
                }
            }
            return item;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Image getImgBackItem() {
        try {
            if (imgBackItem == null) {
                imgBackItem = Utils.loadImage("nen.png");
            }
            return imgBackItem;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getBackItem() {
        try {
            Sprite backItem = new Sprite(getImgBackItem(), getImgBackItem().getWidth() / 7, getImgBackItem().getHeight());
            int[] seq = {2, 6};
            backItem.setFrameSequence(seq);
            return backItem;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getCredit() {
        try {
            Image img = Utils.loadImage("creadit_bonus.png");
            Sprite credit = new Sprite(img, img.getWidth() / 2, img.getHeight());
            int[] seq = {0, 1};
            credit.setFrameSequence(seq);
            credit.setFrame(1);
            return credit;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public Sprite getCup() {
        try {
            Image img = Utils.loadImage("creadit_bonus.png");
            Sprite cup = new Sprite(img, img.getWidth() / 2, img.getHeight());
            int[] seq = {0, 1};
            cup.setFrameSequence(seq);
            cup.setFrame(0);
            return cup;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}
